package com.sugeun.tab;


import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabWidget;

import com.sugeun.stopwatch.R;

public class TabManager extends TabActivity implements TabHost.OnTabChangeListener {
	private static final String TAG = "TabManager";
	private TabHost tabHost;

	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		 requestWindowFeature(Window.FEATURE_NO_TITLE);
		 setContentView(R.layout.tab_manager);
		 tabHost = getTabHost();
		 Intent alarm = new Intent(TabManager.this, com.sugeun.alarm.AlarmMain.class);	 
		 Intent stopwatch = new Intent(TabManager.this, com.sugeun.stopwatch.StopWatchMain.class);	 
		 Intent timer = new Intent(TabManager.this, com.sugeun.timer.TimerMain.class);
		
		 
		 addTabHost(alarm, stopwatch, timer);
		 tabHost.setOnTabChangedListener(this);  
	}
	
	private void addTabHost(Intent alarm, Intent stopwatch, Intent timer) {
		// TODO Auto-generated method stub
		 tabHost.addTab(tabHost.newTabSpec(getText(R.string.alarm).toString())
		            .setIndicator(TabWidget.inflate(this, R.layout.tab_alarm, null))                
		            .setContent(alarm));
		 tabHost.addTab(tabHost.newTabSpec(getText(R.string.app_name).toString())
		            .setIndicator(TabWidget.inflate(this, R.layout.tab_stopwatch, null))                
		            .setContent(stopwatch));
		 tabHost.addTab(tabHost.newTabSpec(getText(R.string.timer).toString())
		            .setIndicator(TabWidget.inflate(this, R.layout.tab_timer, null))                
		            .setContent(timer));               
	}

	public void onTabChanged(String tabId) {
		// TODO Auto-generated method stub
		 Activity activity = getLocalActivityManager().getActivity(tabId);
		 if (activity != null) {
		        Log.d(TAG, "not null -> onTabChanged : " + tabId);
		            activity.onWindowFocusChanged(true);
		        }
	}

}
